

import 'package:flutter/material.dart';
import 'package:get/get.dart';


class AppServiceState {

  late final ThemeData darkTheme;
  late final ThemeData lightTheme;
  final RxBool _isDarkMode = Get.isDarkMode.obs;
  bool get isDarkMode => _isDarkMode.value;
  set isDarkMode(bool value) => _isDarkMode.value = value;
}


class AppService extends GetxService {

  AppServiceState state = AppServiceState();

  Future<AppService> init() async {

    return this;
  }

  // 切换主题
  void toggleTheme() {
    state.isDarkMode = !state.isDarkMode;
    if (state.isDarkMode) {
      Get.changeTheme(state.darkTheme);
    } else {
      Get.changeTheme(state.lightTheme);
    }
  }

  // 切换指定主题
  void setTheme(bool isDark) {
    state.isDarkMode = isDark;
    if (state.isDarkMode) {
      Get.changeTheme(state.darkTheme);
    } else {
      Get.changeTheme(state.lightTheme);
    }

  }
}